
var api = require('../../utils/api.js');
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        switch1Checked: 0,
        i:0,
        endt:'',
        addt:'',
        id:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getmyorder();
    },

    getmyorder(){
        var that=this;
        api.post({
            url: 'worker/getbang',
            data: {},
            success: data => {

                var nows=data.data;

                that.setData({
                    lists:data.data,
                    addt:nows[0].addt,
                    endt:nows[0].endt,
                    id:nows[0].id,
                    switch1Checked:nows[0].status,
                })
            
            }
        })
    },

    getmyorders(){
        var that=this;
        api.post({
            url: 'worker/getbang',
            data: {},
            success: data => {
                that.setData({
                    lists:data.data,
                })
            
            }
        })
    },

    bindTimeChangea(ret){
        console.log(ret);

        

        this.setData({
            addt:ret.detail.value
        })
    },
    bindTimeChangeb(ret){
        console.log(ret);
        this.setData({
            endt:ret.detail.value
        })
    },

    switch1Change(ret){
        console.log(ret);
        var val=ret.detail.value;

        if(val){
            val=1;
        }else{
            val=0;
        }

        this.setData({
            switch1Checked:val
        })
    },

    getthedate(ret){
        console.log(ret);
        var index=ret.currentTarget.dataset.i;
        var list=this.data.lists;

        this.setData({
            i:index,
            addt:list[index].addt,
            endt:list[index].endt,
            id:list[index].id,
            switch1Checked:list[index].status,
        })

    },
    saves(){
        var id=this.data.id;
        var addt=this.data.addt;
        var endt=this.data.endt;
        var switch1Checked=this.data.switch1Checked;
        var that=this;
        api.post({
            url: 'worker/setbang',
            data: {id:id,addt:addt,endt:endt,status:switch1Checked},
            success: data => {

                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })

                if(data.code==0){
                    return false;
                }

                that.getmyorders();
            
            }
        })

    }
})